<template>
	<view>
		<image class="acCover" :src="acCover" mode=""></image>
		<view class="title">{{acTitle}}</view>
		<view class="content_box">
			<view class="box" v-for="(item,index) in acTag" :key="index" :class="{'special' : item== '线下活动'}">
				{{item}}
			</view>
		</view>
		<view class="time">
			<image class="time_icon" src="https://img.wilmer.com.cn/admin/2024/Group%20266.png" mode=""></image>
			{{Timeprocessing(acSatrt)}} 至 {{Timeprocessing(acFinish)}}
		</view>
		<view class="neirong">
			<view class="title">活动具体内容</view>
			<image class="acImg" :src="acImg" mode="" @click="lookImg()" :style="{height: imgHeight + 'px'}">
			</image>
		</view>
		<view style="height: 60rpx;"></view>
	</view>
</template>

<script>
	import {
		activityId
	} from '@/common/api/homePage.js'
	export default {
		data() {
			return {
				id: "",
				acCover: "", // 封面
				acTitle: "", // 标题
				acTag: [],
				acSatrt: "", // 开始时间
				acFinish: "", // 结束时间
				acImg: "", // 内容
				imgHeight: 0 // 图片高度
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getData()
		},
		methods: {
			getData() {
				uni.showLoading({
					title: '加载中'
				});
				activityId(this.id).then(res => {
					setTimeout(() => {
						uni.hideLoading();
					}, 500)
					this.acCover = res.data.data.acCover
					this.acTitle = res.data.data.acTitle
					this.acSatrt = res.data.data.acSatrt
					this.acFinish = res.data.data.acFinish
					this.acImg = res.data.data.acImg
					uni.getImageInfo({
						src: this.acImg,
						success: res => {
							this.imgHeight = 328 * res.height / res.width
							console.log(328 * res.height / res.width)
						}
					});
					if (res.data.data.acTag) {
						this.acTag = res.data.data.acTag.split(',')
					}
				})
			},
			lookImg() {
				uni.previewImage({
					current: 0,
					urls: [this.acImg]
				})
			},
			Timeprocessing(originalDateTimeStr) {
				if (originalDateTimeStr) {
					const originalDate = new Date(originalDateTimeStr);
					const year = originalDate.getFullYear();
					const month = originalDate.getMonth() + 1; // 月份从 0 开始，所以要加 1
					const date = originalDate.getDate();
					const hours = originalDate.getHours();
					const minutes = originalDate.getMinutes();
					const targetDateTimeStr =
						`${year}-${month < 10 ? '0' + month : month}-${date < 10 ? '0' + date : date} ${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}`;
					return targetDateTimeStr
				} else {
					return ''
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.acCover {
		display: block;
		width: 686rpx;
		height: 336rpx;
		margin: 20rpx auto 0;
		border-radius: 20rpx;
	}

	.title {
		font-family: Branding-BoldItalic;
		font-size: 28rpx;
		font-weight: 500;
		margin-left: 34rpx;
		margin-top: 20rpx;
		letter-spacing: -0.1em;
	}

	.content_box {
		margin-top: 20rpx;
		margin-left: 34rpx;
		display: flex;

		.box {
			font-family: Branding-BoldItalic;
			font-size: 24rpx;
			font-weight: 400;
			color: #666666;
			padding: 12rpx 18rpx;
			border-radius: 8rpx;
			background: #F8F8F8;
			margin-right: 12rpx;
		}
		.special {
			background: #56B0BD;
			color: #fff;
		}
	}

	.time {
		margin-left: 34rpx;
		margin-top: 20rpx;
		display: flex;
		align-items: center;

		.time_icon {
			width: 32rpx;
			height: 32rpx;
			margin-right: 8rpx;
		}

		font-family: Branding-BoldItalic;
		font-size: 28rpx;
		font-weight: 500;
		color: #000000;
	}

	.neirong {
		width: 686rpx;
		border-radius: 6px;
		box-shadow: 0px 1px 4px 1px #00000026;
		margin: 24rpx auto 0;
		padding: 28rpx 0;

		.title {
			font-family: Branding-BoldItalic;
			font-size: 28rpx;
			font-weight: 500;
			margin-left: 18rpx;
		}

		.acImg {
			display: block;
			max-width: 656rpx;
			height: 6000px;
			margin: 28rpx auto 0;
		}
	}
</style>